{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "Draw the PCA (Principal Component Analysis) ellipsoid that contains\n",
    "50% of a cloud of Points, then check if points are inside the surface.\n",
    "Extra info is stored in object.info['sphericity'], 'va', 'vb', 'vc'.\n",
    "\"\"\"\n",
    "from vedo import *\n",
    "import numpy as np\n",
    "\n",
    "vp = Plotter()\n",
    "\n",
    "pts = np.random.randn(500, 3) # random gaussian point cloud\n",
    "\n",
    "elli = pcaEllipsoid(pts, pvalue=0.5)  # group of [ellipse, 3 axes]\n",
    "vp += elli\n",
    "\n",
    "ipts = elli.insidePoints(pts) # select points inside mesh\n",
    "opts = elli.insidePoints(pts, invert=True)\n",
    "vp += Points(ipts, c=\"g\")\n",
    "vp += Points(opts, c=\"r\")\n",
    "\n",
    "printc(\"inside  points #\", ipts.N(), c='g')\n",
    "printc(\"outside points #\", opts.N(), c='r')\n",
    "printc(\"a-sphericity:\", elli.asphericity())\n",
    "vp.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "closePlotter()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
